package zaphod.toy.gef.japanexample.model;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import zaphod.toy.gef.japanexample.editparts.ContentsEditPart;
import zaphod.toy.gef.japanexample.editparts.HelloEditPart;


public class MyEditPartFactory implements EditPartFactory
{

    public EditPart createEditPart( EditPart context, Object model )
    {
        EditPart part = null;
        if ( model == null )
            throw new RuntimeException( "Model is null" );
        if ( model instanceof HelloModel )
        {
            part = new HelloEditPart();
        }

        if ( model instanceof ContentsModel )
        {
            part = new ContentsEditPart();
        }

        if ( part != null )
        {
            part.setModel( model );
            return part;
        }

        throw new RuntimeException( "No corressponding model : "
                + model.getClass().getName() );
    }

}
